package com.tidc.seaservermodel.config;

import com.tidc.seaservermodel.entity.RabbitMessageLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @ClassNmae RabbitConfig
 * @Description
 * @Author 冯涛滔
 **/
@Configuration
@Slf4j
public class RabbitConfig {
    @Autowired
    CachingConnectionFactory cachingConnectionFactory;

    @Bean
    RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
        return new RabbitAdmin(connectionFactory);
    }

    //  check配置
    @Bean
    DirectExchange checkExchange() {
        return new DirectExchange(RabbitConstants.CHECK_EXCHANGE_NAME, true, false);
    }

    //checkTask
    @Bean
    public Queue checkTaskOutQueue() {
        return new Queue(RabbitConstants.CHECK_TASK_OUT_QUEUE_NAME);
    }

    @Bean
    Binding checkTaskOutBinding() {
        return BindingBuilder.bind(checkTaskOutQueue()).to(checkExchange()).with(RabbitConstants.CHECK_TASK_OUT_ROUTING_KEY_NAME);
    }

    //    checkCommitment
    @Bean
    public Queue seaCheckCommitmentOutQueue() {
        return new Queue(RabbitConstants.CHECK_COMMITMENT_OUT_QUEUE_NAME);
    }

    @Bean
    Binding seaCheckCommitmentOutBinding() {
        return BindingBuilder.bind(seaCheckCommitmentOutQueue()).to(checkExchange()).with(RabbitConstants.CHECK_COMMITMENT_OUT_ROUTING_KEY_NAME);
    }

    //    checkClearRabbit
    @Bean
    public Queue checkClearRabbitQueue() {
        return new Queue(RabbitConstants.CHECK_CLEAR_RABBIT_QUEUE_NAME);
    }

    @Bean
    Binding checkClearRabbitBinding() {
        return BindingBuilder.bind(checkClearRabbitQueue()).to(checkExchange()).with(RabbitConstants.CHECK_CLEAR_RABBIT_ROUTING_KEY_NAME);
    }

    //  email配置
    @Bean
    DirectExchange emailExchange() {
        return new DirectExchange(RabbitConstants.EMAIl_EXCHANGE_NAME, true, false);
    }

    //    sendEmail
    @Bean
    public Queue sendEmailQueue() {
        return new Queue(RabbitConstants.SEND_EMAIl_QUEUE_NAME);
    }

    @Bean
    Binding sendEmailBinding() {
        return BindingBuilder.bind(sendEmailQueue()).to(emailExchange()).with(RabbitConstants.SEND_EMAIl_ROUTING_KEY_NAME);
    }

    //    Experience配置
    @Bean
    DirectExchange experienceExchange() {
        return new DirectExchange(RabbitConstants.EXPERIENCE_EXCHANGE_NAME, true, false);
    }
//    addExperience
    @Bean
    public Queue addExperienceQueue() {
        return new Queue(RabbitConstants.ADD_EXPERIENCE_QUEUE_NAME);
    }
    @Bean
    Binding addExperienceBinding() {
        return BindingBuilder.bind(addExperienceQueue()).to(experienceExchange()).with(RabbitConstants.ADD_EXPERIENCE_ROUTING_KEY_NAME);
    }
//    punishmentExperience
    @Bean
    public Queue punishmentExperienceQueue() {
        return new Queue(RabbitConstants.PUNISHMENT_EXPERIENCE_QUEUE_NAME);
    }
    @Bean
    Binding punishmentExperienceBinding() {
        return BindingBuilder.bind(punishmentExperienceQueue()).to(experienceExchange()).with(RabbitConstants.PUNISHMENT_EXPERIENCE_ROUTING_KEY_NAME);
    }



}
